/**
 * 软件著作权：东方汇创
 *
 * 系统名称：  xxx项目
 *
 * 文件名称：  RoleController.java
 *
 * 功能描述：  rm_roleController
 * 
 * 版本历史：
 * 
 * 2018-06-13   1.0.0版 （龙色波）（创建文件）
 */

package org.quickbundle.orgauth.rmrole.web;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.quickbundle.config.RmConfig;
import org.quickbundle.orgauth.IOrgauthConstants;
import org.quickbundle.orgauth.rmrole.service.IRmRoleService;
import org.quickbundle.orgauth.rmrole.util.IRmRoleConstants;
import org.quickbundle.orgauth.rmrole.vo.RmRoleVo;
import org.quickbundle.project.RmProjectHelper;
import org.quickbundle.project.common.vo.RmCommonVo;
import org.quickbundle.project.login.RmUserVo;
import org.quickbundle.tools.helper.RmSqlHelper;
import org.quickbundle.tools.helper.RmVoHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dfhc.ISystemConstant;
import com.dfhc.pub.concurrencycontrol.RequestConcurrentLockException;
import com.dfhc.pub.concurrencycontrol.RequestConcurrentRoute;
import com.dfhc.util.JspHelper;
import com.dfhc.util.StringHelper;
import com.dfhc.util.XssHelper;

/**
 * rm_role Controller
 * 
 * @author 龙色波
 * @see 参见的类
 */
@Controller
@RequestMapping(value = "/rmrole")
public class HRoleController implements IRmRoleConstants {

    @Autowired
    /**
     * rm_role服务
     */
    private IRmRoleService roleService;

    /**
     * 简单查询，分页显示，支持表单回写
     * @param model 模型
     * @param request http请求对象
     * @return 跳转的列表jsp     
     */
    @RequestMapping(value = "")
    public String list(Model model, HttpServletRequest request) {
        return "/qb5activiti/rm/rmrole/listRole";
    }
    
    /**
     * ajax 请求列表数据
     * @param model
     * @param request
     * @return
     * @throws IOException 
     */
    @RequestMapping(value = "ajaxList",  produces="application/json")
    @ResponseBody
    public Map<String,Object> ajaxList(Model model, HttpServletRequest request, HttpServletResponse response) throws IOException{
           boolean bLock = false;
           Map<String,Object> dataMap=new HashMap<String,Object>();
           try{
		        XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"
		        bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
		        //获取开始记录数
		        String startRow = request.getParameter(ISystemConstant.PAGE_START_KEY);
		        String rows=request.getParameter(ISystemConstant.PAGE_SIZE_KEY)==null?ISystemConstant.DEFAULT_PAGE_SIZE:request.getParameter(ISystemConstant.PAGE_SIZE_KEY);	        
		        int rowsInt=Integer.parseInt(rows);//页大小
		        if(StringHelper.isEmpty(startRow)){
		        	startRow="0";
		        }
		        int startRowInt = Integer.parseInt(startRow);
		        String searchPara = getQueryCondition(request);  //从request中获得查询条件
		        int totalNum = roleService.getRecordCount(searchPara);   //从request中获得查询条件
		        String orderStr = JspHelper.getOrderStr(request);  //得到排序信息
	        
	        	List<RmRoleVo> beans = roleService.queryByCondition(searchPara, orderStr, startRowInt+1, rowsInt);  //按条件查询全部,带排序
	        	//翻译状态码
	        	if(beans!=null){
	        	for(RmRoleVo bean:beans){
				//如果状态码字段有其他用途，请用扩展字段attribute1-attribute5代替
//				bean.setEnableStatus(RmGlobalReference.get(ISystemConstant.DICTIONARY_RM_ENABLE_STATUS, bean.getEnableStatus()));
//				bean.setIsSystemLevel(RmGlobalReference.get(ISystemConstant.DICTIONARY_RM_YES_NOT, bean.getIsSystemLevel()));
//				bean.setIsRecursive(RmGlobalReference.get(ISystemConstant.DICTIONARY_RM_YES_NOT, bean.getIsRecursive()));
	        	}
        	}         
	        	dataMap.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
		        dataMap.put(ISystemConstant.PAGE_DRAW, request.getParameter(ISystemConstant.PAGE_DRAW));
	        	dataMap.put(ISystemConstant.RECORDS_TOTAL,totalNum);
		        dataMap.put(ISystemConstant.RECORDS_FILTERED, totalNum);
	        	dataMap.put(ISystemConstant.DATA, beans);
	        	return dataMap;
          }catch(RequestConcurrentLockException e){
        	  RmProjectHelper.logInf(StringHelper.exceptionToString(e));
        	  dataMap.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
        	  dataMap.put(ISystemConstant.AJAX_MESSAGE, e.getMessage());
        	  return dataMap;   
          }catch(Exception e){
        	  e.printStackTrace();
        	  RmProjectHelper.logInf(StringHelper.exceptionToString(e));
        	  dataMap.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
        	  dataMap.put(ISystemConstant.AJAX_MESSAGE, "查询失败!");
        	  return dataMap;
          }finally{
	        //最后解锁
	        RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);	        
          }
    }
    
    /**
	 * 功能: 从request中获得查询条件
	 * 
	 * @param request
	 * @return
	 */
	protected String getQueryCondition(HttpServletRequest request) {
		String queryCondition = null;
//        String name =request.getParameter("name");
//        if (request.getParameter("name")!=null) {
//         try {
//			name = new String(request.getParameter("name").getBytes("ISO8859-1"), "UTF-8");
//		} catch (UnsupportedEncodingException e) {
//			e.printStackTrace();
//		}
//		}
        if(request.getAttribute(REQUEST_QUERY_CONDITION) != null) {  //如果request.getAttribute中有，就不取request.getParameter
            queryCondition = request.getAttribute(REQUEST_QUERY_CONDITION).toString();
        } else {
			List<String> lQuery = new ArrayList<String>();
			
				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".role_code", request.getParameter("roleCode"), RmSqlHelper.TYPE_CHAR_LIKE));
				
				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".name", request.getParameter("name"), RmSqlHelper.TYPE_CHAR_LIKE));
				
				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".enable_status", request.getParameter("enableStatus"), RmSqlHelper.TYPE_CHAR_LIKE));
				
				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".is_system_level", request.getParameter("isSystemLevel"), RmSqlHelper.TYPE_CHAR_LIKE));
				
				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".description", request.getParameter("description"), RmSqlHelper.TYPE_CHAR_LIKE));
				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".owner_org_id", request.getParameter("ownerOrgId"), RmSqlHelper.TYPE_CHAR_LIKE));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".is_recursive", request.getParameter("isRecursive"), RmSqlHelper.TYPE_CUSTOM, "='", "'"));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".matrix_code", request.getParameter("matrixCode"), RmSqlHelper.TYPE_CHAR_LIKE));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".function_permission", request.getParameter("functionPermission"), RmSqlHelper.TYPE_CHAR_LIKE));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".data_permission", request.getParameter("dataPermission"), RmSqlHelper.TYPE_CUSTOM, "='", "'"));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".usable_status", request.getParameter("usableStatus"), RmSqlHelper.TYPE_CHAR_LIKE));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".modify_date", request.getParameter("modifyDate"), RmSqlHelper.TYPE_CHAR_LIKE));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".modify_ip", request.getParameter("modifyIp"), RmSqlHelper.TYPE_CHAR_LIKE));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".modify_user_id", request.getParameter("modifyUserId"), RmSqlHelper.TYPE_CHAR_LIKE));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".constraint", request.getParameter("constraint"), RmSqlHelper.TYPE_CHAR_LIKE));
				
			queryCondition = RmSqlHelper.appendQueryStr(lQuery.toArray(new String[0]));
        }
        return queryCondition;
	}
    
    /**
     * 从页面表单获取信息注入vo，并插入单条记录
     * @param request http请求对象
     * @param vo 值对象
     * @return 返回Ajax应答实体对象
     */
    @RequestMapping(value = "insert", method = RequestMethod.POST, 
			consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> insert(HttpServletRequest request, @Valid RmRoleVo vo) throws Exception {
          boolean bLock = false;
          try{
	    	XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
	        RmVoHelper.markCreateStamp(request,vo);  //打创建时间,IP戳
	        Map<String, Object> result = new HashMap<String, Object>();
	        try{
	        	String isSystemLevel = request.getParameter("is_system_level");
	        	String roleCode = request.getParameter("role_code");
	        	vo.setEnable_status("0");
	        	vo.setIs_system_level(isSystemLevel);
	        	vo.setRole_code(roleCode);
		        roleService.insert(vo);
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
		        result.put(ISystemConstant.AJAX_MESSAGE, "新增角色成功!" );
	        }catch(Exception e){
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
		        result.put(ISystemConstant.AJAX_MESSAGE, "新增角色失败!");	        	
	        }
	        return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    
    /**
     * 从页面表单获取信息注入vo，并修改单条记录
     * @param request 请求对象
     * @param vo 值对象
     * @param errors Ajax错误对象
     * @return 返回Ajax应答实体对象
     */
    @RequestMapping(value = "update", method = RequestMethod.POST, 
			consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> update(HttpServletRequest request, @Valid RmRoleVo vo) throws Exception {
          boolean bLock = false;
          try{
	    	XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
        	RmVoHelper.markModifyStamp(request,vo);  //打修改时间,IP戳
	        Map<String, Object> result = new HashMap<String, Object>();
	        try{
	        	String isSystemLevel = request.getParameter("is_system_level");
	        	String roleCode = request.getParameter("role_code");
	        	vo.setEnable_status("0");
	        	vo.setIs_system_level(isSystemLevel);
	        	vo.setRole_code(roleCode);
		        roleService.update(vo);
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
		        result.put(ISystemConstant.AJAX_MESSAGE, "更新角色成功!" );
	        }catch(Exception e){
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
		        result.put(ISystemConstant.AJAX_MESSAGE, "更新角色失败!");	        	
	        }
	        return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
//    /**
//     * 根据id获取单条记录
//     * @param request 请求对象
//     * @param vo 值对象
//     * @param
//     * @return 返回Ajax应答实体对象
//     */
//    @RequestMapping(value = "get/{id}/{dateTime}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
//    @ResponseBody
//    public Map<String,Object> get(@PathVariable("id") String id, HttpServletRequest request) throws Exception {
//          boolean bLock = false;
//          try{
//	    	XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"		        
//	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
//        	RmRoleVo bean = roleService.get(id);
//	        Map<String, Object> result = new HashMap<String, Object>();
//        	if(bean==null){
//	            result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
//        	    result.put(ISystemConstant.AJAX_MESSAGE, "记录没找到(id:"+id+")!");
//	            return result;
//        	}
//        
//	        result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
//        	result.put(ISystemConstant.AJAX_BEAN, bean);
//	        return result;			
//          }finally{
//    		//最后解锁
//    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
//          }
//    }    
//
//   /**
//     * 从页面的表单获取单条记录id并逻辑删除，如request.id为空则删除多条记录（request.ids）
//     * @param request http请求对象
//     * @param redirectAttributes 重定向属性
//     * @return 返回列表页面
//     */
//    @RequestMapping(value = "logicDelete", method = RequestMethod.POST)
//    public String deleteLogic(HttpServletRequest request, RedirectAttributes redirectAttributes) throws Exception {
//          boolean bLock = false;
//          try{
//	    	XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"
//	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
//        	int deleteCount = 0;  //定义成功删除的记录数
//	        String id = request.getParameter(REQUEST_ID);
//        	if(id != null && id.length() > 0) {
//	            deleteCount = roleService.deleteLogic(request,id);
//        	} else {
//	            String[] ids = RmJspHelper.getArrayFromRequest(request, REQUEST_IDS); //从request获取多条记录id
//        	    if (ids != null && ids.length != 0) {
//                	deleteCount += roleService.deleteLogic(request,ids);  //删除多条记录
//	            }
//        	}
//	        redirectAttributes.addFlashAttribute("message", "删除成功: " + deleteCount);
//        	return "redirect:/rmrole?"+ISystemConstant.RM_PARENT_CODE+"="+request.getParameter(ISystemConstant.RM_PARENT_CODE);
//          }finally{
//    		//最后解锁
//    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
//          }
//    }
//    /**
//     * 从页面的表单获取单条记录id，并察看这条记录的详细信息
//     * @param id 待删除的id
//     * @param model 模型
//     * @request 请求对象
//     * @return 返回详细信息页面
//     */
//    @RequestMapping(value = "detail/{id}")
//    public String detail(@PathVariable("id") String id, Model model, HttpServletRequest request) throws Exception {
//          boolean bLock = false;
//          try{
//	    	XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"
//	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
//	        RmRoleVo bean = roleService.get(id);
//	        model.addAttribute(REQUEST_BEAN, bean);  //把vo放入request
//        	if(RM_YES.equals(request.getParameter(REQUEST_IS_READ_ONLY))) {
//	            model.addAttribute(REQUEST_IS_READ_ONLY, request.getParameter(REQUEST_IS_READ_ONLY));
//        	}
//	        return "/qb5activiti/rm/rmrole/detailRole";
//          }finally{
//    	    //最后解锁
//    	    RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
//          }
//    }
//
//    /**
//     * 功能: 从request中获得查询条件
//     *
//     * @param request
//     * @return
//	 * @throws UnsupportedEncodingException 
//     */
//    protected String getQueryCondition(HttpServletRequest request) throws UnsupportedEncodingException {
//        String queryCondition = null;
//        String name =request.getParameter("name");
//        if (request.getParameter("name")!=null) {
//         name = new String(request.getParameter("name").getBytes("ISO8859-1"), "UTF-8");
//		}
//        if(request.getAttribute(REQUEST_QUERY_CONDITION) != null) {  //如果request.getAttribute中有，就不取request.getParameter
//            queryCondition = request.getAttribute(REQUEST_QUERY_CONDITION).toString();
//        } else {
//			List<String> lQuery = new ArrayList<String>();
//			
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".role_code", request.getParameter("role_code"), RmSqlHelper.TYPE_CUSTOM, "='", "'"));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".name", request.getParameter("name"), RmSqlHelper.TYPE_CHAR_LIKE));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".enable_status", name, RmSqlHelper.TYPE_CHAR_LIKE));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".is_system_level", request.getParameter("enable_status"), RmSqlHelper.TYPE_CHAR_LIKE));
//				
//				lQuery.add(RmSqlHelper.buildQueryStr(TABLE_NAME + ".description", request.getParameter("total_code"), RmSqlHelper.TYPE_CHAR_LIKE));
//			queryCondition = RmSqlHelper.appendQueryStr(lQuery.toArray(new String[0]));
//        }
//        return queryCondition;
//    }
//   /**
//     * 详情页
//     * 
//     * @param model
//     * @param request
//     * @return
//     */
//    @RequestMapping(value="toDetail")
//    public String toDetail(Model model, HttpServletRequest request) throws Exception{    	
//          boolean bLock = false;
//          try{
//	    	XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"
//	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
//
//	    	String id=request.getParameter("id");
//    	
//	    	RmRoleVo vo=roleService.get(id);
//    	
//    		model.addAttribute("roleVo", vo);
//    	
//	    	model.addAttribute("id", id);    
//    		return "/qb5activiti/rm/rmrole/detailRole";  
//          }finally{
//    		//最后解锁
//    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
//          }  	
//    }
//   /**
//    * 前台导出通用业务表数据为xls,并下载
//    * @throws Exception 
//    *
//    */
//    @RequestMapping(value="exportXls"+ISystemConstant.SUFFIX_ACTION)
//    public void frontExportXls(Model model,HttpServletRequest request,HttpServletResponse response) throws Exception{	
//          exportXls(model, request, response);
//    }
//   /**
//    * 后台导出通用业务表数据为xls,并下载
//    * @throws Exception 
//    **/
//   @RequestMapping(value="exportXls")
//   public void backExportXls(Model model,HttpServletRequest request,HttpServletResponse response) throws Exception{	
//          exportXls(model, request, response);
//   }
//   /**
//    * 导出xls公共方法
//    * @param model
//    * @param request
//    * @param response
//    * @throws UnsupportedEncodingException
//    */
//   private void exportXls(Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
//          boolean bLock = false;
//          try{
//	    	XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"
//	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
//
//	    	//获取排序
//	    	String order = request.getParameter(ISystemConstant.PREDEFINED_ORDER);
//	    	if(!StringHelper.isEmpty(order)){
//			String order1 = new String(order.getBytes("ISO-8859-1"),"UTF-8");
//		    	order = java.net.URLDecoder.decode(order1, "UTF-8");
//	    	}
//	    	Map<String, Object> searchPara = new HashMap<String,Object>();
//	    	searchPara.put("delete_flag",ISystemConstant.DICTIONARY_RM_YES_NOT_0);
//	    	List<RmRoleVo> vos = roleService.list(searchPara, order);    		
//	    	String sheetName = request.getParameter(ISystemConstant.PREDEFINED_SHELL_NAME);
//	    	if(StringHelper.isEmpty(sheetName)){
//	    		sheetName = ISystemConstant.DEFAULT_SHELL_NAME;
//	    	}
//	    	LinkedHashMap<String,String> fieldMap = new LinkedHashMap<String,String>();
//	    	//获取删除的列名
//	    	String deletes = request.getParameter(ISystemConstant.PREDEFINED_EXPORT_DELETE_COLUMNNAMES);
//	    	List<String> deleteList =  new ArrayList<String>();
//	    	if(!StringHelper.isEmpty(deletes)){
//	    		deleteList = Arrays.asList(deletes.split(","));
//	    	}
//	    	//所有字段放入fieldMap
//	    	fieldMap.put("id","ID");
//	    	fieldMap.put("roleCode","ROLE_CODE");
//	    	fieldMap.put("name","NAME");
//	    	fieldMap.put("enableStatus","ENABLE_STATUS");
//	    	fieldMap.put("isSystemLevel","IS_SYSTEM_LEVEL");
//	    	fieldMap.put("ownerOrgId","OWNER_ORG_ID");
//	    	fieldMap.put("isRecursive","IS_RECURSIVE");
//	    	fieldMap.put("matrixCode","MATRIX_CODE");
//	    	fieldMap.put("description","DESCRIPTION");
//	    	fieldMap.put("functionPermission","FUNCTION_PERMISSION");
//	    	fieldMap.put("dataPermission","DATA_PERMISSION");
//	    	fieldMap.put("usableStatus","USABLE_STATUS");
//	    	fieldMap.put("modifyDate","MODIFY_DATE");
//	    	fieldMap.put("modifyIp","MODIFY_IP");
//	    	fieldMap.put("modifyUserId","MODIFY_USER_ID");
//	    	fieldMap.put("constraint","CONSTRAINT");
//	    	//删除无用字段
//	    	for(String  propertyName:deleteList){
//	    	    if(fieldMap.containsKey(propertyName)){
//	    		fieldMap.remove(propertyName);
//	    		continue;
//	    	    }
//	    	}
//	    	
//	    	//获取需要隐藏的列数组
//	    	String hides = request.getParameter(ISystemConstant.PREDEFINED_EXPORT_HIDE_COLUMNNAMES);
//	    	
//	    	List<String> hideList =  new ArrayList<String>();
//	    	if(!StringHelper.isEmpty(hides)){
//	    		hideList = Arrays.asList(hides.split(","));
//	    	}
//	    	ExcelService.listToExcel(vos, fieldMap, hideList,sheetName, response);		
//          }finally{
//	    	//最后解锁
//	    	RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
//          }
//    }
//    /**
//     * 前台导入通用业务表数据为xls到数据库
//     * @throws Exception 
//     **/
//    @RequestMapping(value="importXls"+ISystemConstant.SUFFIX_ACTION)
//    public void frontImportXls(HttpServletRequest request, HttpServletResponse response) throws Exception{
//    	importXls(request, response);
//    }
//    /**
//     * 后台导入通用业务表数据为xls到数据库
//     * @throws Exception 
//     **/
//    @RequestMapping(value="importXls")
//    public void backImportXls(HttpServletRequest request, HttpServletResponse response) throws Exception{
//    	importXls(request, response);
//    }
//    /**
//     * 导入xls公共方法
//     * @param request
//     * @param response
//     */
//    private void importXls(HttpServletRequest request, HttpServletResponse response) throws Exception {
//          boolean bLock = false;
//          try{
//	    	XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"
//	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
//
//		   try {
//			//获取上传文件xls
//			List<MultipartFile> uploadFiles = FileOperateHelper.listMultipartFile(request);
//			if(uploadFiles==null ||uploadFiles.isEmpty()){
//				throw new PjException("缺少上传文件!");
//			}	
//			String sheetName = request.getParameter(ISystemConstant.PREDEFINED_SHELL_NAME);
//			if(StringHelper.isEmpty(sheetName)){
//		    		sheetName = ISystemConstant.DEFAULT_SHELL_NAME;
//			}
//			LinkedHashMap<String,String> fieldMap = new LinkedHashMap<String,String>();
//			String idCnName=null;//id中文名
//
//			idCnName ="ID";
//			fieldMap.put("ID","id");
//			fieldMap.put("ROLE_CODE","roleCode");
//			fieldMap.put("NAME","name");
//			fieldMap.put("ENABLE_STATUS","enableStatus");
//			fieldMap.put("IS_SYSTEM_LEVEL","isSystemLevel");
//			fieldMap.put("OWNER_ORG_ID","ownerOrgId");
//			fieldMap.put("IS_RECURSIVE","isRecursive");
//			fieldMap.put("MATRIX_CODE","matrixCode");
//			fieldMap.put("DESCRIPTION","description");
//			fieldMap.put("FUNCTION_PERMISSION","functionPermission");
//			fieldMap.put("DATA_PERMISSION","dataPermission");
//			fieldMap.put("USABLE_STATUS","usableStatus");
//			fieldMap.put("MODIFY_DATE","modifyDate");
//			fieldMap.put("MODIFY_IP","modifyIp");
//			fieldMap.put("MODIFY_USER_ID","modifyUserId");
//			fieldMap.put("CONSTRAINT","constraint");
//
//			MultipartFile mfile = uploadFiles.get(0);
//		    	
//			List<RmRoleVo> vos =null;
//			InputStream inputStream = null;
//			try{
//				inputStream = mfile.getInputStream();
//				if(!StringHelper.isEmpty(idCnName)){
//					vos = ExcelService.excelToList(inputStream, sheetName, RmRoleVo.class, fieldMap, new String[]{idCnName});
//				}else{
//					vos = ExcelService.excelToList(inputStream, sheetName, RmRoleVo.class, fieldMap, new String[]{});
//				}
//			}finally{
//				if(inputStream!=null){
//					inputStream.close();
//					inputStream = null;
//				}
//			}
//			roleService.insertUpdateBatch(vos); 
//			
//		   } catch (Exception e) {
//			e.printStackTrace();
//			Map<String, Object> result = new HashMap<String, Object>();//
//			result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
//			String PjException = "com.dfhc.PjException:";
//			result.put(ISystemConstant.AJAX_MESSAGE, e.getMessage().substring(e.getMessage().indexOf(PjException)+PjException.length()));
//			response.setContentType("text/html;charset=utf-8");
//			try {
//				response.getWriter().print(JSONObject.toJSONString(result));
//				response.getWriter().flush();
//			} catch (Exception ex) {
//				ex.printStackTrace();
//			}
//			return;
//		   }
//		   Map<String, Object> result = new HashMap<String, Object>();
//		   result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
//		   result.put(ISystemConstant.AJAX_MESSAGE, "导入成功!");
//		   response.setContentType("text/html;charset=utf-8");
//		   try {
//			response.getWriter().print(JSONObject.toJSONString(result));
//			response.getWriter().flush();
//		   } catch (IOException e) {
//			e.printStackTrace();
//		   }
//          }finally{
//		   //最后解锁
//		   RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
//          }
//    }
//    /**
//     * ajax逻辑删除
//     * @param request http请求对象
//     * @param redirectAttributes 重定向属性
//     * @return 返回列表页面
//    */
//    @RequestMapping(value = "ajaxLogicDelete", method = RequestMethod.POST, 
//    consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
//    @ResponseBody
//    public Map<String, Object> ajaxLogicDelete(HttpServletRequest request) throws Exception {
//          Map<String, Object> result = new HashMap<String, Object>();
//          boolean bLock = false;
//          try{
//	    	XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"
//	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
//
//
//	        String id = request.getParameter(REQUEST_ID);
//        	if(id != null && id.length() > 0) {
//	            roleService.deleteLogic(request,id);
//        	} else {
//	            String[] ids = RmJspHelper.getArrayFromRequest(request, REQUEST_IDS); //从request获取多条记录id
//        	    if (ids != null && ids.length != 0) {
//                	roleService.deleteLogic(request,ids);  //删除多条记录
//	            }
//        	}
//        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
//        	result.put(ISystemConstant.AJAX_MESSAGE, "删除成功!");
//        	return result;
//          }finally{
//    		//最后解锁
//    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
//          }
//    }
    /**
     * 删除记录
     * @param request http请求对象
     * @return 返回列表页面
    */
    @RequestMapping(value = "delete", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String, Object> delete(HttpServletRequest request) throws Exception {
          boolean bLock = false;
          try{
	    	XssHelper.check(request,null);//校验请求数据是否含XSS攻击"关键字"
        	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));        	
	        Map<String, Object> result = new HashMap<String, Object>();
	        try{
		        roleService.delete(request.getParameter(REQUEST_ID));
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
		        result.put(ISystemConstant.AJAX_MESSAGE, "删除rm_role成功!" );
	        }catch(Exception e){
	        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
		        result.put(ISystemConstant.AJAX_MESSAGE, "删除rm_role失败!");	        	
	        }
	        return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    /**
     * 跳转到新增页面
     * @param model 模型
     * @param request http请求对象
     * @return 跳转的列表jsp     
     */
    @RequestMapping(value = "addPage")
    public String addPage(Model model, HttpServletRequest request) {    	            
          return "/qb5activiti/rm/rmrole/addRole";
    }
    /**
     * 跳转到授权页面
     * @param model 模型
     * @param request http请求对象
     * @return 跳转的列表jsp     
     */
    @RequestMapping(value = "authorization")
    public String authorization(Model model, HttpServletRequest request) { 
          return "/qb5activiti/rm/rmrole/authorization";
    }
    /**
     * 跳转到编辑和查看页面
     * @param model 模型
     * @param request http请求对象
     * @return 跳转的列表jsp     
     */
    @RequestMapping(value = "showPage")
    public String showPage(Model model, HttpServletRequest request) {
          //获取id
          String id = request.getParameter(REQUEST_ID);
          //根据id查询rm_role
          if(!StringHelper.isEmpty(id)){
    		RmRoleVo vo = roleService.find(id);
    		model.addAttribute(REQUEST_BEAN, vo);
          }
          return "/qb5activiti/rm/rmrole/addRole";
    }
    
//    /**
//     * 得到缓存中查询条件对应的count(*)记录数，如返回-1则执行查询
//     * 
//     * @param queryCondition
//     * @return
//     */
//    protected int getCount(String queryCondition) {
//    	int count = RmSqlCountCache.getCount(TABLE_NAME, queryCondition);
//    	if(count < 0) {
//    		count =iRmFunctionNodeService.getRecordCount(queryCondition);
//    		RmSqlCountCache.putCount(TABLE_NAME, queryCondition, count);
//    	}
//    	return count;
//    }
}
